import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { PetColor } from "../pet/info/PetColor";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { DataEvent } from "../../events/DataEvent";
import { PetMeetEventName } from "./info/PetMeetEventName";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { ColorInfo } from "../../resource/info/ColorInfo";
//class PetMeetPetSelectRender
    
    export  class PetMeetPetSelectRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            this.mouseEnabled = true;
            this.mouseChildren = false;
            addEventListener(flash.events.MouseEvent.ROLL_OVER, this.onMouseOver);
            addEventListener(flash.events.MouseEvent.ROLL_OUT, this.onMouseOut);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._petInfo = arg1 as SPetInfo;
            if (this._petInfo) 
            {
                this._talentColor = PetColor.getTalentColorByTalent(this._petInfo.gene, this._petInfo.talent);
                this._nameText.htmlText = HTMLUtil.addColor(this._petInfo.name, this._talentColor.color);
                this._levelTxt.text = this._petInfo.level.toString();
            }
            return;
        }

        /* internal  */init(): void
        {
            graphics.beginFill(16777215, 0);
            graphics.drawRect(0, 0, 150, 20);
            graphics.endFill();
            this._nameText = new Object /* flash.text.TextField */();
            this._nameText.mouseEnabled = false;
            this._nameText.selectable = false;
            this._nameText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._nameText.x = 10;
            this.addChild(this._nameText);
            ObjCreate.createTextField("等级：", 100, 0, 70, 20, this);
            this._levelTxt = ObjCreate.createTextField("", 135, 0, 70, 20, this);
            this._overSkin = GlobalClass.getScaleBitmap(ImagesConst.Friend_over);
            this._overSkin.width = 150;
            this._overSkin.height = 20;
            this._overSkin.x = 5;
            return;
        }

        /* internal  */onMouseOver(arg1: Object /* flash.events.MouseEvent */): void
        {
            addChildAt(this._overSkin, 0);
            return;
        }

        /* internal  */onMouseOut(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!_selected) 
            {
                if (this._overSkin.parent) 
                {
                    removeChild(this._overSkin);
                }
            }
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (arg1) 
            {
                addChildAt(this._overSkin, 0);
                if (this._petInfo) 
                {
                    this.dispatchEvent(new DataEvent(PetMeetEventName.SelectedPet, this._petInfo, false, true));
                }
            }
            else if (this._overSkin.parent) 
            {
                removeChild(this._overSkin);
            }
            return;
        }

        /* internal */ /* var */_nameText: Object /* flash.text.TextField */;

        /* internal */ /* var */_levelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_overSkin: ScaleBitmap;

        /* internal */ /* var */_petInfo: SPetInfo;

        /* internal */ /* var */_talentColor: ColorInfo;
    }
